package com.digitalchina.lxnsy.activity.old;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.bigkoo.pickerview.OptionsPickerView;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessFile;
import com.digitalchina.lxnsy.api.BusinessPlan;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.entity.AgriculturalSchemaVO;
import com.digitalchina.lxnsy.entity.FarmRecordVarietyVO;
import com.digitalchina.lxnsy.entity.FileVO;
import com.digitalchina.lxnsy.entity.LandVO;
import com.digitalchina.lxnsy.entity.OperationRecordsVO;
import com.digitalchina.lxnsy.entity.PlanProductVO;
import com.digitalchina.lxnsy.entity.SchemaJsonVO;
import com.digitalchina.lxnsy.entity.SchemeListVO;
import com.digitalchina.lxnsy.loader.GlideImageLoader;
import com.digitalchina.lxnsy.toolkit.DateStyle;
import com.digitalchina.lxnsy.toolkit.DateUtil;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.MathExtend;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.toolkit.SharedPreferencesUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.xml.AdminXML;
import com.digitalchina.lxnsy.xml.UserXML;
import com.facebook.drawee.view.SimpleDraweeView;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageGridActivity;
import com.lzy.okhttputils.model.HttpParams;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/8/27 15:45
 * 修改备注：
 * ================================================
 */
public class AddFarmingRecordActivityV2 extends BaseActivity {


    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.layout_time)
    RelativeLayout layoutTime;
    @Bind(R.id.tv_weather)
    TextView tvWeather;
    @Bind(R.id.layout_weather)
    RelativeLayout layoutWeather;
    @Bind(R.id.tv_phenological)
    TextView tvPhenological;
    @Bind(R.id.layout_phenological)
    RelativeLayout layoutPhenological;
    @Bind(R.id.flow_layout)
    TagFlowLayout flowLayout;
    @Bind(R.id.et_fertilizer)
    EditText etFertilizer;
    @Bind(R.id.sdv_img0)
    SimpleDraweeView sdvImg0;
    @Bind(R.id.sdv_img1)
    SimpleDraweeView sdvImg1;
    @Bind(R.id.sdv_img2)
    SimpleDraweeView sdvImg2;
    @Bind(R.id.sdv_img3)
    SimpleDraweeView sdvImg3;
    @Bind(R.id.et_msg_info)
    EditText etMsgInfo;
    @Bind(R.id.bt_save)
    Button btSave;
    @Bind(R.id.tv_land)
    TextView tvLand;
    @Bind(R.id.layout_land)
    RelativeLayout layoutLand;
    @Bind(R.id.tv_variety)
    TextView tvVariety;
    @Bind(R.id.layout_variety)
    RelativeLayout layoutVariety;
    @Bind(R.id.layout_nongyao)
    LinearLayout layoutNongyao;
    @Bind(R.id.layout_huafei)
    LinearLayout layoutHuafei;
    @Bind(R.id.et_mu_num)
    EditText etMuNum;
    @Bind(R.id.et_work_time)
    EditText etWorkTime;
    @Bind(R.id.et_people_num)
    EditText etPeopleNum;
    @Bind(R.id.et_people_name)
    EditText etPeopleName;
    @Bind(R.id.et_dapeng)
    EditText etDapeng;
    @Bind(R.id.layout_dapeng)
    LinearLayout layoutDapeng;
    @Bind(R.id.et_jxsb)
    EditText etJxsb;
    @Bind(R.id.layout_jxsb)
    LinearLayout layoutJxsb;
    @Bind(R.id.layout_trp)
    LinearLayout layoutTrp;
    @Bind(R.id.et_jsff)
    EditText etJsff;
    @Bind(R.id.layout_jsff)
    LinearLayout layoutJsff;
    @Bind(R.id.et_jgbz)
    EditText etJgbz;
    @Bind(R.id.layout_caishou)
    LinearLayout layoutCaishou;
    @Bind(R.id.layout_jiagong)
    LinearLayout layoutJiagong;
    @Bind(R.id.show_ny_hf)
    LinearLayout showNyHf;
    @Bind(R.id.show_dapeng)
    LinearLayout showDapeng;
    @Bind(R.id.show_jxsb)
    LinearLayout showJxsb;
    @Bind(R.id.show_jsff)
    LinearLayout showJsff;
    @Bind(R.id.show_jgbz)
    LinearLayout showJgbz;
    @Bind(R.id.layout_dingzhi)
    LinearLayout layoutDingzhi;

    private TagAdapter<PlanProductVO.FarmOperationBean> tagAdapter; // 单选适配器
    private List<PlanProductVO.FarmOperationBean> farmList = new ArrayList<>(); // 农事操作list


    /**
     * 新版参数
     *
     * @param productionId 生产计划Id
     * @param userAccId 用户Id
     * @param operationDate  操作日期
     * @param weather  天气
     * @param weatherDescribe 天气描述
     * @param phId 物后期Id
     * @param phaseName 物后期名称
     * @param farmingOperations 农事操作Id (多个以“，”隔开)
     * @param farmingOperationsimgs 图片多个以，隔开
     * @param specification 补充说明
     * @param perMuTotal 亩数总量
     * @param pesticideFertilizerList 农事记录管理农药、肥料Json字符串
     * @param id 农事记录Id
     */

    private String productionId = "";
    private String operationDate = "";
    private String weather = "";
    private String weatherDescribe = "";
    private String phId = "";
    private String phaseName = "";
    //    private String farmingOperations = ""; // 农事操作Id (多个以“，”隔开)
    private String farmingOperationsimgs = "";
    private String specification = "";
    //    private String perMuTotal = "";
//    private String pesticideFertilizerList = "";
    private String id = "";

    // 时间选择器
//    private TimePickerView pvTime;
    private OptionsPickerView pvWeather, pvPhase;

    //农药、化肥、大棚、机械设备、投入品、技术方法、采收、加工包装
    private OptionsPickerView pvNy, pvHf, pvDp, pvJxsb, pvTrp, pvDz, pvYm, pvCs, pvJg;

    private List<String> listT = new ArrayList<>();
    private List<List<String>> listW = new ArrayList<>();

    private PlanProductVO planProductVO;
    // 物候期
    private List<PlanProductVO.ProductStandardBean.PhaseMsgInfosBean> whList = new ArrayList<>();
    private List<String> emptyList = new ArrayList<>();
    // 新增药剂/肥料list
//    private List<PesticideFertilizerVO> fertilizerList = new ArrayList<>();
    // 农事记录ID 修改时用
//    private String agriculturalRecordsId = "";


    // 图片
    public static final int IMAGE_ITEM_ADD = -1;
    public static final int REQUEST_CODE_SELECT = 100;
    private ImagePicker imagePicker;
    private String[] imgs = {"", "", "", ""};
    private SimpleDraweeView[] sdvArray = new SimpleDraweeView[4];

    private int select = 0;

    private String inTime = "";// 进入时间
    private String faroutTime = "";//农事保存退出时间
    private String outTime = "";//   离开时间(通用)

    private OperationRecordsVO recordVO;

    int mYear;
    int mMonth;
    int mDayOfMonth;

    /**
     * 2019年7月10日 10:01:28
     */
    private OptionsPickerView pvLand, pvVariety; // 地块 品种
    private String landParcelInfoId = ""; // 地块ID
    private String varietyId = ""; // 品种ID
    private List<LandVO> landList; // 地块list
    private List<FarmRecordVarietyVO> varietyList; // 品种list
    private String muNumber = "";//亩数
    private String hours = "";//工时
    private String peopleNum = "";//人数
    private String member = "";//人员
    private String schemaListStr = ""; //方案集合
    private String farmOperationId = "";// 作物管理ID
    private List<SchemeListVO> fertilizerSchemeList = new ArrayList(); //化肥
    private List<SchemeListVO> pesticideSchemeList = new ArrayList(); //农药
    private List<SchemeListVO> manageItemsRowsSchemeList = new ArrayList();//大棚管理
    private List<SchemeListVO> machineryEquipmentSchemeList = new ArrayList();//机械设备
    private List<SchemeListVO> inProductSchemeList = new ArrayList();//投入品
    private List<SchemeListVO> technicalMethodsSchemeList = new ArrayList();//技术方法 （2019年7月17日 16:49:25修改为育苗）
    private List<SchemeListVO> harvestPackagingSchemeList = new ArrayList();//采收包装
    private List<SchemeListVO> processedPackagingSchemeList = new ArrayList();//加工包装
    private List<SchemeListVO> colonizationSchemeList = new ArrayList();//定值 2019年7月17日 16:49:18新增
    private AgriculturalSchemaVO agriculturalSchemaVO;
    private List<SchemaJsonVO> schemaJsonList = new ArrayList<>();
    private boolean isRemoveAllViews = true;

    private DatePickerDialog datePickerDialog;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (StringUtil.isStrEmpty(faroutTime)) {
            outTime = DateUtil.getCurrentDate(DateStyle.YYYY_MM_DD_EN_HH_MM_SS_EN);
            BusinessPlan.saveStayOftenInfo(this, productionId, "0", inTime, faroutTime, outTime, mHandler);
        }
    }

    @Override
    public void setLayout() {
        inTime = DateUtil.getCurrentDate(DateStyle.YYYY_MM_DD_EN_HH_MM_SS_EN);
        //TODO 这里是layout
        setContentLayout(R.layout.activity_add_farming_record_v2);
        setTitle("新增农事记录");

        //从ERP进入
        if (AdminXML.getFarmOperation(activity).equals("1")) {
            layoutLand.setVisibility(View.VISIBLE);
            getLandList();
        } else {
            layoutLand.setVisibility(View.GONE);
        }

    }

    @Override
    public void initMember() {

        emptyList.add("");

        Calendar calendar = Calendar.getInstance();
        mYear = calendar.get(Calendar.YEAR);
        mMonth = calendar.get(Calendar.MONTH);
        mDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

        operationDate = mYear + "-" + (mMonth + 1) + "-" + mDayOfMonth;
        tvTime.setText(operationDate);


        String w = SharedPreferencesUtil.getValue(this, UserXML.XML_NAME_USER, "curWeather", "");

        if (!StringUtil.isStrEmpty(w)) {
            tvWeather.setText(w);
            String s[] = w.split(" ");
            weather = s[0];
            weatherDescribe = s[1];
        }

        sdvArray[0] = sdvImg0;
        sdvArray[1] = sdvImg1;
        sdvArray[2] = sdvImg2;
        sdvArray[3] = sdvImg3;

        if (getIntent().hasExtra("OperationRecordsVO")) { // 修改进入
            recordVO = (OperationRecordsVO) getIntent().getSerializableExtra("OperationRecordsVO");
            productionId = recordVO.getProductionId();
            setView();
        } else if (getIntent().hasExtra("map")) { // 生产计划详情进入
            Map<String, String> map = (Map<String, String>) getIntent().getSerializableExtra("map");
            phaseName = map.get("phaseName");
            phId = map.get("phId");
            tvPhenological.setText(phaseName);
            productionId = map.get("productionId");
            farmOperationId = map.get("farmOptId");
            getAgriculturalSchema();
        } else {// 新增按钮进入
            productionId = getIntent().getStringExtra("productionId");
        }

        //获取品种
        getVariety();

        // 获取物候期
        BusinessPlan.productionShow(this, productionId, mHandler);
        // 获取农药
        BusinessPlan.getPesticideData(this, mHandler);

        initOptPicker();

    }

    // 获取地块
    private void getLandList() {
        HttpParams params = new HttpParams();
        params.put("enterpriseId", AdminXML.getEnterpriseId(activity));
        params.put("resNo", AdminXML.getResNo(activity));

        OkHttpUtil.post(activity, URL.URL_GET_LAND_LIST, "", params, mHandler,
                MSG_S_2, MSG_F_2);
    }

    // 获取品种
    private void getVariety() {
        HttpParams params = new HttpParams();
        params.put("enterpriseId", AdminXML.getEnterpriseId(activity));
        params.put("resNo", AdminXML.getResNo(activity));
        params.put("productPlanId", productionId);

        OkHttpUtil.post(activity, URL.URL_GET_FARM_OPERATION, "", params, mHandler,
                MSG_S_1, MSG_F_1);
    }

    //如果是修改则加载带入数据
    private void setView() {
        //公共部分
        id = recordVO.getId();
        phId = recordVO.getPhaseId();
        operationDate = recordVO.getOperationDate();
        tvTime.setText(operationDate);
        weather = recordVO.getWeather();
        weatherDescribe = recordVO.getWeatherDescribe();
        tvWeather.setText(weather + " " + weatherDescribe);
        phaseName = recordVO.getPhaseName();
        tvPhenological.setText(phaseName);
        // 图片
        if (recordVO.getFarmingOperationsimgs() != null && recordVO.getFarmingOperationsimgs().size() > 0) {
            for (int i = 0; i < recordVO.getFarmingOperationsimgs().size(); i++) {
                imgs[i] = recordVO.getFarmingOperationsimgs().get(i).getImage();
                FrescoUtil.showImageSmall(imgs[i], sdvArray[i]);
            }
        }
        // 说明
        specification = recordVO.getSpecification();
        etMsgInfo.setText(specification);

        //农事操作ID
        farmOperationId = recordVO.getFarmOperationId();
        isRemoveAllViews = false;
        getAgriculturalSchema();


        //品种
        tvVariety.setText(recordVO.getVarietyName());
        varietyId = recordVO.getVarietyId();

        //地块
        if (recordVO.getLandId() != null && recordVO.getLandName() != null) {
            tvLand.setText(recordVO.getLandName());
            landParcelInfoId = recordVO.getLandId();
        }

        etMuNum.setText(recordVO.getMuNumber());
        etWorkTime.setText(recordVO.getHours());
        etPeopleNum.setText(recordVO.getPeopleNum());
        etPeopleName.setText(recordVO.getMember());


        modView(recordVO.getAgriculturalOperationSchemeVO());
    }

    @Override
    public void addListener() {
        flowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                tagAdapter.setSelectedList(position);
                farmOperationId = farmList.get(position).getId();
                isRemoveAllViews = true;
                getAgriculturalSchema();
                return false;
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                if (isFinishing())
                    return;

                switch (msg.what) {
                    case MSG.MSG_PRODUCTION_SHOW_SUCCESS:// 获取物候期
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_PRODUCTION_SHOW_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_FARMING_SAVE_SUCCESS: // 提交表单
                        showToast("保存成功");
                        faroutTime = DateUtil.getCurrentDate(DateStyle.YYYY_MM_DD_EN_HH_MM_SS_EN);
                        BusinessPlan.saveStayOftenInfo(AddFarmingRecordActivityV2.this, productionId, "0", inTime, faroutTime, outTime, mHandler);
                        setResult(RESULT_OK);
                        finish();
                        break;
                    case MSG.MSG_FARMING_SAVE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_FILE_UPLOAD_SUCCESS: // 上传图片
                        dismissDialog();
                        FileVO fileVO = FastJsonUtil.getBean(msg.obj.toString(), "fileStorage", FileVO.class);
                        if (fileVO != null) {
                            imgs[select] = fileVO.getName();
                            setImageView(fileVO.getName());
                        }
                        break;
                    case MSG.MSG_FILE_UPLOAD_FIELD:
                        dismissDialog();
                        showToast(msg.obj.toString() + "");
                        break;
                    case MSG_S_1:
                        setVariety(msg.obj);
                        break;
                    case MSG_S_2:
                        setLand(msg.obj);
                        break;
                    case MSG_S_3:
                        setScheme(msg.obj);
                        break;
                }
            }
        };
    }

    //设置方案
    private void setScheme(Object obj) {

        agriculturalSchemaVO = FastJsonUtil.getBean(obj.toString(), "agriculturalSchema", AgriculturalSchemaVO.class);

        if (agriculturalSchemaVO != null) {
            fertilizerSchemeList = agriculturalSchemaVO.getFertilizerSchemeList();
            pesticideSchemeList = agriculturalSchemaVO.getPesticideSchemeList();
            manageItemsRowsSchemeList = agriculturalSchemaVO.getManageItemsRowsSchemeList();
            machineryEquipmentSchemeList = agriculturalSchemaVO.getMachineryEquipmentSchemeList();
            inProductSchemeList = agriculturalSchemaVO.getInProductSchemeList();
            technicalMethodsSchemeList = agriculturalSchemaVO.getTechnicalMethodsSchemeList();
            harvestPackagingSchemeList = agriculturalSchemaVO.getHarvestPackagingSchemeList();
            processedPackagingSchemeList = agriculturalSchemaVO.getProcessedPackagingSchemeList();
            colonizationSchemeList = agriculturalSchemaVO.getColonizationSchemeList();

            if (fertilizerSchemeList != null && fertilizerSchemeList.size() > 0) {
                pvHf.setPicker(fertilizerSchemeList);
            }

            if (pesticideSchemeList != null && pesticideSchemeList.size() > 0) {
                pvNy.setPicker(pesticideSchemeList);
            }

            if (machineryEquipmentSchemeList != null && machineryEquipmentSchemeList.size() > 0) {
                pvJxsb.setPicker(machineryEquipmentSchemeList);
            }
            if (inProductSchemeList != null && inProductSchemeList.size() > 0) {
                pvTrp.setPicker(inProductSchemeList);
            }
            if (colonizationSchemeList != null && colonizationSchemeList.size() > 0) {
                pvDz.setPicker(colonizationSchemeList);
            }

            if (technicalMethodsSchemeList != null && technicalMethodsSchemeList.size() > 0) {
                pvYm.setPicker(technicalMethodsSchemeList);
            }

            if (harvestPackagingSchemeList != null && harvestPackagingSchemeList.size() > 0) {
                pvCs.setPicker(harvestPackagingSchemeList);
            }
            if (processedPackagingSchemeList != null && processedPackagingSchemeList.size() > 0) {
                pvJg.setPicker(processedPackagingSchemeList);
            }
        }


        if(isRemoveAllViews){
            layoutNongyao.removeAllViews();
            layoutHuafei.removeAllViews();
            layoutDapeng.removeAllViews();
            layoutJxsb.removeAllViews();
            layoutTrp.removeAllViews();
            layoutJsff.removeAllViews();
            layoutCaishou.removeAllViews();
            layoutJiagong.removeAllViews();


            //隐藏显示农药化肥
            if ((fertilizerSchemeList != null && fertilizerSchemeList.size() > 0) || (pesticideSchemeList != null && pesticideSchemeList.size() > 0)) {
                showNyHf.setVisibility(View.VISIBLE);
            } else {
                showNyHf.setVisibility(View.GONE);
            }

            //隐藏显示大棚管理
            if (manageItemsRowsSchemeList != null && manageItemsRowsSchemeList.size() > 0) {
                pvDp.setPicker(manageItemsRowsSchemeList);
                showDapeng.setVisibility(View.VISIBLE);
            } else {
                showDapeng.setVisibility(View.GONE);
            }



            //隐藏显示机械设备（投入品）
            if ((machineryEquipmentSchemeList != null && machineryEquipmentSchemeList.size() > 0) || (inProductSchemeList != null && inProductSchemeList.size() > 0)) {
                showJxsb.setVisibility(View.VISIBLE);
            } else {
                showJxsb.setVisibility(View.GONE);
            }




            //隐藏显示技术方法
            if ((technicalMethodsSchemeList != null && technicalMethodsSchemeList.size() > 0) || (colonizationSchemeList != null && colonizationSchemeList.size() > 0)) {
                showJsff.setVisibility(View.VISIBLE);
            } else {
                showJsff.setVisibility(View.GONE);
            }



            //隐藏显示采收包装加工
            if ((harvestPackagingSchemeList != null && harvestPackagingSchemeList.size() > 0) || (processedPackagingSchemeList != null && processedPackagingSchemeList.size() > 0)) {
                showJgbz.setVisibility(View.VISIBLE);
            } else {
                showJgbz.setVisibility(View.GONE);
            }

        }









    }


    //设置品种
    private void setVariety(Object obj) {

        varietyList = FastJsonUtil.getListBean(obj.toString(), "varieties", FarmRecordVarietyVO.class);


        pvVariety = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                tvVariety.setText(varietyList.get(options1).getPickerViewText());
                varietyId = varietyList.get(options1).getId();
            }
        })
                .setTitleText("品种")
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvVariety.setPicker(varietyList);

    }

    //设置地块
    private void setLand(Object obj) {

        landList = FastJsonUtil.getListBean(obj.toString(), "landParcelInfoVOList", LandVO.class);


        pvLand = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                tvLand.setText(landList.get(options1).getPickerViewText());
                landParcelInfoId = landList.get(options1).getLandParcelId();
            }
        })
                .setTitleText("地块")
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvLand.setPicker(landList);

    }

    private void setImageView(String fileName) {
        FrescoUtil.showImageSmall(fileName, sdvArray[select]);
    }

    @Override
    public void callBack(Object object) {

        planProductVO = FastJsonUtil.getBean(object.toString(), "productPlan", PlanProductVO.class);

        if (planProductVO != null && planProductVO.getProductStandard() != null) {

            // 农事操作列表
            farmList = planProductVO.getPhaseMsgInfo().getFarmOperation();

            // 物候期
            whList = planProductVO.getProductStandard().getPhaseMsgInfos();
            pvPhase.setPicker(whList);

            int ints[] = new int[1];

            if (getIntent().hasExtra("productionId")) {
                phId = planProductVO.getPhaseMsgInfo().getId();
                phaseName = planProductVO.getPhaseMsgInfo().getPhaseName();
                tvPhenological.setText(phaseName + "");

                tagAdapter.setData(farmList);
            } else {

                // 修改记录的时候遍历已选中
                if (recordVO != null) {
                    if (farmList != null && farmList.size() > 0) {
                        for (int i = 0; i < farmList.size(); i++) {
                            if (farmList.get(i).getId().equals(recordVO.getFarmOperationId())) {
                                ints[0] = i;
                                break;
                            }
                        }

                        tagAdapter.setData(farmList);
                        tagAdapter.setSelectedList(ints);
                    }
                } else {
                    if (farmList != null)
                        farmList.clear();

                    for (int i = 0; i < whList.size(); i++) {
                        if (phId.equals(whList.get(i).getId())) {
                            farmList = whList.get(i).getFarmOperation();
                            break;
                        }
                    }


                    if (farmList != null && farmList.size() > 0) {

                        for (int i = 0; i < farmList.size(); i++) {
                            if (farmList.get(i).getId().equals(farmOperationId)) {
                                ints[0] = i;
                                break;
                            }
                        }

                        tagAdapter.setData(farmList);
                        tagAdapter.setSelectedList(ints);
                    }
                }
            }


        }

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.layout_time, R.id.layout_weather, R.id.layout_phenological, R.id.layout_select_fertilizer, R.id.sdv_img1, R.id.sdv_img2, R.id.sdv_img3, R.id.sdv_img0,
            R.id.bt_save, R.id.tv_add_fertilizer, R.id.layout_land, R.id.layout_variety, R.id.layout_select_dapeng, R.id.tv_add_dapeng, R.id.layout_select_jxsb,
            R.id.tv_add_jxsb, R.id.layout_select_jsff, R.id.tv_add_jsff, R.id.layout_select_jgbz, R.id.tv_add_jgbz})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_save:

                saveFarm();

                break;
            case R.id.layout_time:
                showDatePicker();
                break;
            case R.id.layout_weather:
                pvWeather.show();
                break;
            case R.id.layout_phenological:
                pvPhase.show();
                break;
            case R.id.sdv_img0:
                selectImage(0);
                break;
            case R.id.sdv_img1:
                selectImage(1);
                break;
            case R.id.sdv_img2:
                selectImage(2);
                break;
            case R.id.sdv_img3:
                selectImage(3);
                break;
            case R.id.layout_select_fertilizer:// 化肥选择
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                selectFertilizer();
                break;
            case R.id.tv_add_fertilizer: // 自定义添加化肥农药
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                addFertilizer();
                break;
            case R.id.layout_land: // 地块
                if (landList == null || landList.size() <= 0)
                    showToast("正在获取地块");
                else
                    pvLand.show();
                break;
            case R.id.layout_variety: // 品种
                if (varietyList == null || varietyList.size() <= 0)
                    showToast("正在获取品种");
                else
                    pvVariety.show();
                break;
            case R.id.layout_select_dapeng: // 大棚选择
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                if (agriculturalSchemaVO == null) {
                    showToast("请先选择作物管理项目");
                    return;
                }
                if (manageItemsRowsSchemeList != null && manageItemsRowsSchemeList.size() > 0)
                    pvDp.show();
                else
                    showToast("暂无数据");
                break;
            case R.id.tv_add_dapeng: // 自定义大棚管理
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                addDaPeng();
                break;
            case R.id.layout_select_jxsb: // 机械设备
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                selectJxsb();
                break;
            case R.id.tv_add_jxsb: // 自定义机械设备
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                addJxsb();
                break;
            case R.id.layout_select_jsff: // 技术方法
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                selectJsff();
                break;
            case R.id.tv_add_jsff: // 自定义技术方法
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                addJsff();
                break;
            case R.id.layout_select_jgbz: // 加工包装
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                selectJgbz();
                break;
            case R.id.tv_add_jgbz: // 自定义加工包装
                if (StringUtil.isEditEmpty(etMuNum)) {
                    showToast("请先填写亩数！");
                    return;
                }
                addJgbz();
                break;
        }
    }

    private void addJsff() {
        if (StringUtil.isEditEmpty(etJsff)) {
            showToast("请填写技术方法");
        } else {
            new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                    .title("您添加的“" + etJsff.getText().toString() + "”是定值还是育苗？")
                    .items(R.array.isJsff)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                            if (position == 0)
                                layoutDingzhi.addView(newView(8, etJsff.getText().toString(), "9", "", "", ""));
                            else
                                layoutJsff.addView(newView(5, etJsff.getText().toString(), "3", "", "", ""));

                            etJsff.setText("");
                        }
                    })
                    .show();
        }
    }

    private void selectJsff() {
        if (agriculturalSchemaVO == null) {
            showToast("请先选择作物管理项目");
        } else {

            new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                    .title("请选择类型")
                    .items(R.array.isJsff)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                            if (position == 0) {
                                if (colonizationSchemeList != null && colonizationSchemeList.size() > 0)
                                    pvDz.show();
                                else
                                    showToast("暂无数据");

                            } else {
                                if (technicalMethodsSchemeList != null && technicalMethodsSchemeList.size() > 0)
                                    pvYm.show();
                                else
                                    showToast("暂无数据");

                            }
                        }
                    })
                    .show();
        }

    }

    private void addJgbz() {
        if (StringUtil.isEditEmpty(etJgbz)) {
            showToast("请填写加工包装");
        } else {
            new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                    .title("您添加的“" + etJgbz.getText().toString() + "”是机械还是投入品？")
                    .items(R.array.isJgbz)
                    .itemsCallback(new MaterialDialog.ListCallback() {
                        @Override
                        public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                            if (position == 0)
                                layoutCaishou.addView(newView(6, etJgbz.getText().toString(), "7", "", "", ""));
                            else
                                layoutJiagong.addView(newView(7, etJgbz.getText().toString(), "8", "", "", ""));

                            etJgbz.setText("");
                        }
                    })
                    .show();
        }
    }

    private void selectJgbz() {
        if (agriculturalSchemaVO == null) {
            showToast("请先选择作物管理项目");
            return;
        }

        new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                .title("请选择类型")
                .items(R.array.isJgbz)
                .itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                        if (position == 0) {
                            if (harvestPackagingSchemeList != null && harvestPackagingSchemeList.size() > 0)
                                pvCs.show();
                            else
                                showToast("暂无数据");

                        } else {
                            if (processedPackagingSchemeList != null && processedPackagingSchemeList.size() > 0)
                                pvJg.show();
                            else
                                showToast("暂无数据");

                        }
                    }
                })
                .show();
    }


    private void addDaPeng() {
        if (StringUtil.isEditEmpty(etDapeng)) {
            showToast("请填写管理项");
        } else {
            layoutDapeng.addView(newView(2, etDapeng.getText().toString(), "6", "", "", ""));
            etDapeng.setText("");
        }

    }


    private void addJxsb() {
        if (StringUtil.isEditEmpty(etJxsb)) {
            showToast("请填写机械/投入品");
            return;
        }

        new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                .title("您添加的“" + etJxsb.getText().toString() + "”是机械还是投入品？")
                .items(R.array.isJxsb)
                .itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                        if (position == 0)
                            layoutJxsb.addView(newView(3, etJxsb.getText().toString(), "4", "", "", ""));
                        else
                            layoutTrp.addView(newView(4, etJxsb.getText().toString(), "5", "", "", ""));

                        etJxsb.setText("");
                    }
                })
                .show();
    }

    private void addFertilizer() {
        if (StringUtil.isEditEmpty(etFertilizer)) {
            showToast("请填写药剂/化肥");
            return;
        }

        new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                .title("您添加的“" + etFertilizer.getText().toString() + "”是农药还是肥料？")
                .items(R.array.isAddWater)
                .itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                        if (position == 0)
                            layoutNongyao.addView(newView(0, etFertilizer.getText().toString(), "2", "", "", ""));
                        else
                            layoutHuafei.addView(newView(1, etFertilizer.getText().toString(), "1", "", "", ""));


                        etFertilizer.setText("");
                    }
                })
                .show();
    }

    private void selectJxsb() {
        if (agriculturalSchemaVO == null) {
            showToast("请先选择作物管理项目");
            return;
        }

        new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                .title("请选择类型")
                .items(R.array.isJxsb)
                .itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                        if (position == 0) {
                            if (machineryEquipmentSchemeList != null && machineryEquipmentSchemeList.size() > 0)
                                pvJxsb.show();
                            else
                                showToast("暂无数据");

                        } else {
                            if (inProductSchemeList != null && inProductSchemeList.size() > 0)
                                pvTrp.show();
                            else
                                showToast("暂无数据");

                        }
                    }
                })
                .show();
    }

    private void selectFertilizer() {
        if (agriculturalSchemaVO == null) {
            showToast("请先选择作物管理项目");
            return;
        }

        new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                .title("请选择类型")
                .items(R.array.isAddWater)
                .itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                        if (position == 0) {
                            if (pesticideSchemeList != null && pesticideSchemeList.size() > 0)
                                pvNy.show();
                            else
                                showToast("暂无数据");

                        } else {
                            if (fertilizerSchemeList != null && fertilizerSchemeList.size() > 0)
                                pvHf.show();
                            else
                                showToast("暂无数据");

                        }
                    }
                })
                .show();
    }


    /**
     * 显示日期选择
     */
    private void showDatePicker() {


        if (datePickerDialog == null) {
            datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                    operationDate = year + "-" + (month + 1) + "-" + dayOfMonth;
                    tvTime.setText(operationDate);
                }
            }, mYear, mMonth, mDayOfMonth);
        } else {
            datePickerDialog.show();
        }

    }


    /**
     * 方案类型 1-肥料 2-农药 3-技术方法 4-机械设备 5-投入品 6-管理项 7-采收包装 8-加工包装
     */
    // 动态新增view -- 新增用
    private View newView(int i, String name, String code, final String isYES, final String standard, final String bzID) {

        final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
        ImageView ivDelete = view.findViewById(R.id.iv_delete);
        TextView tvName = view.findViewById(R.id.tv_name);
        TextView tvCode = view.findViewById(R.id.tv_code);
        final TextView tvYN = view.findViewById(R.id.tv_Y_N);
        TextView tvBzID = view.findViewById(R.id.tv_bz_id);
        final EditText etUse = view.findViewById(R.id.et_use);
        final EditText etMuUse = view.findViewById(R.id.et_mu_use);
        View v2 = view.findViewById(R.id.v2);
        LinearLayout layout2 = view.findViewById(R.id.layout2);
        View v3 = view.findViewById(R.id.v3);
        LinearLayout layout3 = view.findViewById(R.id.layout3);
        View v4 = view.findViewById(R.id.v4);
        LinearLayout layout4 = view.findViewById(R.id.layout4);
        final EditText et3 = view.findViewById(R.id.et3);
        final EditText et4 = view.findViewById(R.id.et4);
        EditText et5 = view.findViewById(R.id.et5);
        final EditText et6 = view.findViewById(R.id.et6);
        EditText et7 = view.findViewById(R.id.et7);
        EditText et8 = view.findViewById(R.id.et8);
        Switch swUnit = view.findViewById(R.id.sw_unit);
        TextView tvStandard = view.findViewById(R.id.tv_standard);

        tvName.setText(name);
        tvCode.setText(code);
        tvYN.setText(isYES);
        tvBzID.setText(bzID);

        if (StringUtil.isStrEmpty(standard)) {
            tvStandard.setVisibility(View.GONE);
        }

        tvStandard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                tvYN.setText("YES");
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                tvYN.setText("NO");
                            }
                        })
                        .show();
            }
        });

        switch (i) {
            case 0://农药
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutNongyao.removeView(view);
                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                break;
            case 1:// 化肥
                swUnit.setVisibility(View.GONE);
                etUse.setHint("肥料用量（kg）");
                etMuUse.setHint("亩用量（kg/亩）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutHuafei.removeView(view);
                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                break;
            case 2:// 大棚管理
                swUnit.setVisibility(View.GONE);
                etUse.setHint("行数（行）");
                etMuUse.setHint("株数（株）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutDapeng.removeView(view);
                    }
                });
                break;
            case 3:// 机械设备
                swUnit.setVisibility(View.GONE);
                etUse.setHint("油耗（L）");
                etMuUse.setHint("亩油耗（L/亩）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutJxsb.removeView(view);
                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                break;
            case 4:// 投入品
                swUnit.setVisibility(View.GONE);
                v2.setVisibility(View.VISIBLE);
                layout2.setVisibility(View.VISIBLE);
                etUse.setHint("地膜（kg）");
                etMuUse.setHint("亩用量（kg/亩）");
                et3.setHint("滴灌带用量（m）");
                et4.setHint("亩用量（m/亩）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutTrp.removeView(view);
                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                //动态计算亩用量2
                et4.setFocusable(false);
                et3.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(et3.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            et4.setText(MathExtend.divide(et3.getText().toString(), etMuNum.getText().toString()));
                        else
                            et4.setText("");
                    }
                });
                break;
            case 5:// 技术方法-育苗
                swUnit.setVisibility(View.GONE);
                v2.setVisibility(View.VISIBLE);
                layout2.setVisibility(View.VISIBLE);
                v3.setVisibility(View.VISIBLE);
                layout3.setVisibility(View.VISIBLE);
                etUse.setHint("育苗（个）");
                etMuUse.setHint("穴盘（个）");
                et3.setHint("基质（袋）");
                et4.setHint("浇水（次）");
                et5.setHint("种子（袋）");
                et6.setHint("出苗时间");

                et6.setFocusable(false);
                et6.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DatePickerDialog datePickerDialog = new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
                            @Override
                            public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                                String date = year + "-" + (month + 1) + "-" + dayOfMonth;
                                et6.setText(date);
                            }
                        }, mYear, mMonth, mDayOfMonth);
                        datePickerDialog.show();
                    }
                });
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutJsff.removeView(view);
                    }
                });
                break;
            case 6:// 采收
                swUnit.setVisibility(View.GONE);
                v2.setVisibility(View.VISIBLE);
                layout2.setVisibility(View.VISIBLE);
                etUse.setHint("采收重量（kg）");
                etMuUse.setHint("亩采收重量（kg/亩）");
                et3.setHint("包装规格");
                et3.setInputType(InputType.TYPE_CLASS_TEXT);
                et4.setHint("批次（次）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutCaishou.removeView(view);
                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                break;
            case 7:// 加工包装
                swUnit.setVisibility(View.GONE);
                v2.setVisibility(View.VISIBLE);
                layout2.setVisibility(View.VISIBLE);
                v3.setVisibility(View.VISIBLE);
                layout3.setVisibility(View.VISIBLE);
                v4.setVisibility(View.VISIBLE);
                layout4.setVisibility(View.VISIBLE);
                etUse.setHint("加工件数（个）");
                etMuUse.setHint("加工重量（kg）");
                et3.setHint("人均加工件数（件）");
                et4.setHint("包装箱（含袋/个）");
                et5.setHint("冰袋（个）");
                et6.setHint("包装绳（斤）");
                et7.setHint("包装材料费（元）");
                et8.setHint("冷库预冷费（元）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutJiagong.removeView(view);
                    }
                });
                break;
            case 8:// 技术方法-育苗
                swUnit.setVisibility(View.GONE);
                etUse.setHint("株数（个）");
                etMuUse.setHint("亩株数（个/亩）");
                ivDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        layoutDingzhi.removeView(view);

                    }
                });
                //动态计算亩用量
                etMuUse.setFocusable(false);
                etUse.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                            etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                        else
                            etMuUse.setText("");
                    }
                });
                break;
        }

        return view;


    }


    // 动态新增view -- //TODO 修改用
    private void modView(OperationRecordsVO.AgriculturalOperationSchemeVOBean vo) {

        if (vo != null) {
            //农药
            final List<SchemaJsonVO> list1 = vo.getPesticideSchemeList();
            if ((list1 != null && list1.size() > 0)) {
                showNyHf.setVisibility(View.VISIBLE);
                for (int i = 0; i < list1.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    final EditText etUse = view.findViewById(R.id.et_use);
                    final EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list1.get(i).getName());
                    tvCode.setText(list1.get(i).getType());
                    if (!StringUtil.isStrEmpty(list1.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list1.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list1.get(i).getIsStandardEnforcement());

                    etUse.setHint("农药用量");
                    etMuUse.setHint("亩用量");
                    etUse.setText(list1.get(i).getUseNumber());
                    etMuUse.setText(list1.get(i).getMuNumber());

                    if (!StringUtil.isStrEmpty(list1.get(i).getUnit())) {
                        swUnit.setVisibility(View.VISIBLE);
                        if ("ml".equals(list1.get(i).getUnit())) {
                            swUnit.setChecked(true);
                        } else {
                            swUnit.setChecked(false);
                        }
                    } else {
                        swUnit.setVisibility(View.GONE);
                    }

                    //动态计算亩用量
                    etMuUse.setFocusable(false);
                    etUse.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                            else
                                etMuUse.setText("");
                        }
                    });


                    final String standard = list1.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list1.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutNongyao.removeView(view);
                        }
                    });

                    layoutNongyao.addView(view);
                }
            }

            //化肥
            final List<SchemaJsonVO> list2 = vo.getFertilizerSchemeList();
            if ((list2 != null && list2.size() > 0)) {
                showNyHf.setVisibility(View.VISIBLE);
                for (int i = 0; i < list2.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    final EditText etUse = view.findViewById(R.id.et_use);
                    final EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list2.get(i).getName());
                    tvCode.setText(list2.get(i).getType());
                    if (!StringUtil.isStrEmpty(list2.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list2.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list2.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    etUse.setHint("肥料用量（kg）");
                    etMuUse.setHint("亩用量（kg/亩）");
                    etUse.setText(list2.get(i).getUseNumber());
                    etMuUse.setText(list2.get(i).getMuNumber());

                    //动态计算亩用量
                    etMuUse.setFocusable(false);
                    etUse.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                            else
                                etMuUse.setText("");
                        }
                    });

                    final String standard = list2.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list2.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutHuafei.removeView(view);
                        }
                    });

                    layoutHuafei.addView(view);
                }
            }

            //大棚管理
            final List<SchemaJsonVO> list3 = vo.getManageItemsRowsSchemeList();
            if ((list3 != null && list3.size() > 0)) {
                showDapeng.setVisibility(View.VISIBLE);
                for (int i = 0; i < list3.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    EditText etUse = view.findViewById(R.id.et_use);
                    EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list3.get(i).getName());
                    tvCode.setText(list3.get(i).getType());
                    if (!StringUtil.isStrEmpty(list3.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list3.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list3.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    etUse.setHint("行数（行）");
                    etMuUse.setHint("株数（株）");
                    etUse.setText(list3.get(i).getRowsNumber());
                    etMuUse.setText(list3.get(i).getTreeNumber());

                    final String standard = list3.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list3.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutDapeng.removeView(view);
                        }
                    });

                    layoutDapeng.addView(view);
                }
            }

            //机械设备
            final List<SchemaJsonVO> list4 = vo.getMachineryEquipmentSchemeList();
            if ((list4 != null && list4.size() > 0)) {
                showJxsb.setVisibility(View.VISIBLE);
                for (int i = 0; i < list4.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    final EditText etUse = view.findViewById(R.id.et_use);
                    final EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list4.get(i).getName());
                    tvCode.setText(list4.get(i).getType());
                    if (!StringUtil.isStrEmpty(list4.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list4.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list4.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    etUse.setHint("油耗（L）");
                    etMuUse.setHint("亩油耗（L/亩）");
                    etUse.setText(list4.get(i).getUseNumber());
                    etMuUse.setText(list4.get(i).getMuNumber());

                    //动态计算亩用量
                    etMuUse.setFocusable(false);
                    etUse.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                            else
                                etMuUse.setText("");
                        }
                    });

                    final String standard = list4.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list4.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutJxsb.removeView(view);
                        }
                    });

                    layoutJxsb.addView(view);
                }
            }

            //投入品
            final List<SchemaJsonVO> list5 = vo.getInProductSchemeList();
            if ((list5 != null && list5.size() > 0)) {
                showJxsb.setVisibility(View.VISIBLE);
                for (int i = 0; i < list5.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    final EditText etUse = view.findViewById(R.id.et_use);
                    final EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    final EditText et3 = view.findViewById(R.id.et3);
                    final EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list5.get(i).getName());
                    tvCode.setText(list5.get(i).getType());
                    if (!StringUtil.isStrEmpty(list5.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list5.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list5.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    v2.setVisibility(View.VISIBLE);
                    layout2.setVisibility(View.VISIBLE);

                    etUse.setHint("地膜（kg）");
                    etMuUse.setHint("亩用量（kg/亩）");
                    et3.setHint("滴灌带用量（m）");
                    et4.setHint("亩用量（m/亩）");
                    etUse.setText(list5.get(i).getFilmNumber());
                    etMuUse.setText(list5.get(i).getFilmMuNumber());
                    et3.setText(list5.get(i).getDripDosage());
                    et4.setText(list5.get(i).getDripMuDosage());

                    //动态计算亩用量
                    etMuUse.setFocusable(false);
                    etUse.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                            else
                                etMuUse.setText("");
                        }
                    });
                    //动态计算亩用量2
                    et4.setFocusable(false);
                    et3.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(et3.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                et4.setText(MathExtend.divide(et3.getText().toString(), etMuNum.getText().toString()));
                            else
                                et4.setText("");
                        }
                    });


                    final String standard = list5.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list5.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutTrp.removeView(view);
                        }
                    });

                    layoutTrp.addView(view);
                }
            }

            //技术方法-定值
            final List<SchemaJsonVO> list6a = vo.getTechnicalMethodsSchemeList();
            if ((list6a != null && list6a.size() > 0)) {
                showJsff.setVisibility(View.VISIBLE);
                for (int i = 0; i < list6a.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    EditText etUse = view.findViewById(R.id.et_use);
                    EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    final EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list6a.get(i).getName());
                    tvCode.setText(list6a.get(i).getType());
                    if (!StringUtil.isStrEmpty(list6a.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list6a.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list6a.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);


                    etUse.setHint("株数（个）");
                    etMuUse.setHint("亩株数（个/亩）");

                    et6.setFocusable(false);
                    et6.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            DatePickerDialog datePickerDialog = new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
                                @Override
                                public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                                    String date = year + "-" + (month + 1) + "-" + dayOfMonth;
                                    et6.setText(date);
                                }
                            }, mYear, mMonth, mDayOfMonth);
                            datePickerDialog.show();
                        }
                    });

                    if (!StringUtil.isStrEmpty(list6a.get(i).getEmergenceTime())) {
                        if (list6a.get(i).getEmergenceTime().length() > 10) {
                            et6.setText(list6a.get(i).getEmergenceTime().substring(0, 10));
                        } else
                            et6.setText(list6a.get(i).getEmergenceTime());
                    }


                    final String standard = list6a.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list6a.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutJsff.removeView(view);
                        }
                    });

                    layoutJsff.addView(view);
                }
            }

            //技术方法-育苗
            final List<SchemaJsonVO> list6 = vo.getTechnicalMethodsSchemeList();
            if ((list6 != null && list6.size() > 0)) {
                showJsff.setVisibility(View.VISIBLE);
                for (int i = 0; i < list6.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    EditText etUse = view.findViewById(R.id.et_use);
                    EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    final EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list6.get(i).getName());
                    tvCode.setText(list6.get(i).getType());
                    if (!StringUtil.isStrEmpty(list6.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list6.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list6.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    v2.setVisibility(View.VISIBLE);
                    layout2.setVisibility(View.VISIBLE);
                    v3.setVisibility(View.VISIBLE);
                    layout3.setVisibility(View.VISIBLE);

                    etUse.setHint("育苗（个）");
                    etMuUse.setHint("穴盘（个）");
                    et3.setHint("基质（袋）");
                    et4.setHint("浇水（次）");
                    et5.setHint("种子（袋）");
                    et6.setHint("出苗时间");
                    etUse.setText(list6.get(i).getSeedlingNumber());
                    etMuUse.setText(list6.get(i).getAcupointPlate());
                    et3.setText(list6.get(i).getMatrixDosage());
                    et4.setText(list6.get(i).getWateringNumber());
                    et5.setText(list6.get(i).getBagNum());

                    et6.setFocusable(false);
                    et6.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            DatePickerDialog datePickerDialog = new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
                                @Override
                                public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
                                    String date = year + "-" + (month + 1) + "-" + dayOfMonth;
                                    et6.setText(date);
                                }
                            }, mYear, mMonth, mDayOfMonth);
                            datePickerDialog.show();
                        }
                    });

                    if (!StringUtil.isStrEmpty(list6.get(i).getEmergenceTime())) {
                        if (list6.get(i).getEmergenceTime().length() > 10) {
                            et6.setText(list6.get(i).getEmergenceTime().substring(0, 10));
                        } else
                            et6.setText(list6.get(i).getEmergenceTime());
                    }


                    final String standard = list6.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list6.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutJsff.removeView(view);
                        }
                    });

                    layoutJsff.addView(view);
                }
            }

            //采收
            final List<SchemaJsonVO> list7 = vo.getHarvestPackagingSchemeList();
            if ((list7 != null && list7.size() > 0)) {
                showJgbz.setVisibility(View.VISIBLE);
                for (int i = 0; i < list7.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    final EditText etUse = view.findViewById(R.id.et_use);
                    final EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list7.get(i).getName());
                    tvCode.setText(list7.get(i).getType());
                    if (!StringUtil.isStrEmpty(list7.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list7.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list7.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    v2.setVisibility(View.VISIBLE);
                    layout2.setVisibility(View.VISIBLE);

                    etUse.setHint("采收重量（kg）");
                    etMuUse.setHint("亩采收重量（kg/亩）");
                    et3.setHint("包装规格");
                    et3.setInputType(InputType.TYPE_CLASS_TEXT);
                    et4.setHint("批次（次）");
                    etUse.setText(list7.get(i).getUseNumber());
                    etMuUse.setText(list7.get(i).getMuNumber());
                    et3.setText(list7.get(i).getPackingSize());
                    et4.setText(list7.get(i).getBatch());

                    //动态计算亩用量
                    etMuUse.setFocusable(false);
                    etUse.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!StringUtil.isStrEmpty(etUse.getText().toString()) && !StringUtil.isStrEmpty(editable.toString()))
                                etMuUse.setText(MathExtend.divide(etUse.getText().toString(), etMuNum.getText().toString()));
                            else
                                etMuUse.setText("");
                        }
                    });


                    final String standard = list7.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list7.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutCaishou.removeView(view);
                        }
                    });

                    layoutCaishou.addView(view);
                }
            }

            //加工包装
            final List<SchemaJsonVO> list8 = vo.getProcessedPackagingSchemeList();
            if ((list8 != null && list8.size() > 0)) {
                showJgbz.setVisibility(View.VISIBLE);
                for (int i = 0; i < list8.size(); i++) {
                    final View view = View.inflate(this, R.layout.item_add_farm_2h, null);
                    ImageView ivDelete = view.findViewById(R.id.iv_delete);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvCode = view.findViewById(R.id.tv_code);
                    final TextView tvYN = view.findViewById(R.id.tv_Y_N);
                    TextView tvbzID = view.findViewById(R.id.tv_bz_id);
                    EditText etUse = view.findViewById(R.id.et_use);
                    EditText etMuUse = view.findViewById(R.id.et_mu_use);
                    View v2 = view.findViewById(R.id.v2);
                    LinearLayout layout2 = view.findViewById(R.id.layout2);
                    View v3 = view.findViewById(R.id.v3);
                    LinearLayout layout3 = view.findViewById(R.id.layout3);
                    View v4 = view.findViewById(R.id.v4);
                    LinearLayout layout4 = view.findViewById(R.id.layout4);
                    EditText et3 = view.findViewById(R.id.et3);
                    EditText et4 = view.findViewById(R.id.et4);
                    EditText et5 = view.findViewById(R.id.et5);
                    EditText et6 = view.findViewById(R.id.et6);
                    EditText et7 = view.findViewById(R.id.et7);
                    EditText et8 = view.findViewById(R.id.et8);
                    Switch swUnit = view.findViewById(R.id.sw_unit);
                    TextView tvStandard = view.findViewById(R.id.tv_standard);

                    tvName.setText(list8.get(i).getName());
                    tvCode.setText(list8.get(i).getType());
                    if (!StringUtil.isStrEmpty(list8.get(i).getFarmOperationSchemeId())) {
                        tvbzID.setText(list8.get(i).getFarmOperationSchemeId());
                    }
                    tvYN.setText(list8.get(i).getIsStandardEnforcement());

                    swUnit.setVisibility(View.GONE);

                    v2.setVisibility(View.VISIBLE);
                    layout2.setVisibility(View.VISIBLE);
                    v3.setVisibility(View.VISIBLE);
                    layout3.setVisibility(View.VISIBLE);
                    v4.setVisibility(View.VISIBLE);
                    layout4.setVisibility(View.VISIBLE);

                    etUse.setHint("加工件数（个）");
                    etMuUse.setHint("加工重量（kg）");
                    et3.setHint("人均加工件数（件）");
                    et4.setHint("包装箱（含袋/个）");
                    et5.setHint("冰袋（个）");
                    et6.setHint("包装绳（斤）");
                    et7.setHint("包装材料费（元）");
                    et8.setHint("冷库预冷费（元）");
                    etUse.setText(list8.get(i).getProcessedNumber());
                    etMuUse.setText(list8.get(i).getProcessedWeight());
                    et3.setText(list8.get(i).getAvgProcessedNumber());
                    et4.setText(list8.get(i).getBoxNumber());
                    et5.setText(list8.get(i).getIcpPack());
                    et6.setText(list8.get(i).getPackingRope());
                    et7.setText(list8.get(i).getPackagingMaterialsFee());
                    et8.setText(list8.get(i).getColdStorageFee());


                    final String standard = list8.get(i).getSchemeStandard();

                    if (StringUtil.isStrEmpty(list8.get(i).getIsStandardEnforcement())) {
                        tvStandard.setVisibility(View.GONE);
                    } else {
                        tvStandard.setVisibility(View.VISIBLE);
                        tvStandard.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                new MaterialDialog.Builder(activity)
                                        .title("参考标准")
                                        .content(standard)
                                        .positiveText("已按标准执行")
                                        .negativeText("未按标准执行")
                                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("YES");
                                            }
                                        })
                                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                                            @Override
                                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                                tvYN.setText("NO");
                                            }
                                        })
                                        .show();
                            }
                        });
                    }

                    ivDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            layoutJiagong.removeView(view);
                        }
                    });

                    layoutJiagong.addView(view);
                }
            }
        }

    }

    //获取所有动态添加的Item，找到控件的id，获取数据
    private void getSchemaJsonList() {
        schemaJsonList.clear();
        schemaListStr = "";
        //农药
        for (int i = 0; i < layoutNongyao.getChildCount(); i++) {
            View view = layoutNongyao.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            Switch swUnit = view.findViewById(R.id.sw_unit);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写农药用量");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写农药亩用量");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setUseNumber(etUse.getText().toString());
            vo.setMuNumber(etMuUse.getText().toString());
            if (swUnit.isChecked()) {
                vo.setUnit(swUnit.getTextOn().toString());
            } else {
                vo.setUnit(swUnit.getTextOff().toString());
            }


            schemaJsonList.add(vo);
        }
        //化肥
        for (int i = 0; i < layoutHuafei.getChildCount(); i++) {
            View view = layoutHuafei.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写化肥用量");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写化肥亩用量");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setUseNumber(etUse.getText().toString());
            vo.setMuNumber(etMuUse.getText().toString());
            vo.setUnit("kg");


            schemaJsonList.add(vo);
        }

        //大棚管理
        for (int i = 0; i < layoutDapeng.getChildCount(); i++) {
            View view = layoutDapeng.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写行数");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写株数");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setRowsNumber(etUse.getText().toString());
            vo.setTreeNumber(etMuUse.getText().toString());


            schemaJsonList.add(vo);
        }

        //机械设备
        for (int i = 0; i < layoutJxsb.getChildCount(); i++) {
            View view = layoutJxsb.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写油耗");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写亩油耗");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setUseNumber(etUse.getText().toString());
            vo.setMuNumber(etMuUse.getText().toString());
            vo.setUnit("L");


            schemaJsonList.add(vo);
        }

        //投入品
        for (int i = 0; i < layoutTrp.getChildCount(); i++) {
            View view = layoutTrp.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            EditText et3 = view.findViewById(R.id.et3);
            EditText et4 = view.findViewById(R.id.et4);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写地膜");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写亩用量");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et3.getText().toString())) {
                showToast("请填写滴灌带用量");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(et4.getText().toString())) {
                showToast("请填写亩用量");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setFilmNumber(etUse.getText().toString());
            vo.setFilmMuNumber(etMuUse.getText().toString());
            vo.setDripDosage(et3.getText().toString());
            vo.setDripMuDosage(et4.getText().toString());


            schemaJsonList.add(vo);
        }

        //技术方法-定值
        for (int i = 0; i < layoutDingzhi.getChildCount(); i++) {
            View view = layoutDingzhi.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            EditText et3 = view.findViewById(R.id.et3);
            EditText et4 = view.findViewById(R.id.et4);
            EditText et5 = view.findViewById(R.id.et5);
            EditText et6 = view.findViewById(R.id.et6);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写株数");
                schemaJsonList.clear();
                break;
            }


            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setUseNumber(etUse.getText().toString());
            vo.setMuNumber(etMuUse.getText().toString());
            vo.setUnit("个");


            schemaJsonList.add(vo);
        }

        //技术方法-育苗
        for (int i = 0; i < layoutJsff.getChildCount(); i++) {
            View view = layoutJsff.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            EditText et3 = view.findViewById(R.id.et3);
            EditText et4 = view.findViewById(R.id.et4);
            EditText et5 = view.findViewById(R.id.et5);
            EditText et6 = view.findViewById(R.id.et6);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写育苗");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写穴盘");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et3.getText().toString())) {
                showToast("请填写基质");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(et4.getText().toString())) {
                showToast("请填写浇水");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et5.getText().toString())) {
                showToast("请填写种子");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et6.getText().toString())) {
                showToast("请填写出苗时间");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setSeedlingNumber(etUse.getText().toString());
            vo.setAcupointPlate(etMuUse.getText().toString());
            vo.setMatrixDosage(et3.getText().toString());
            vo.setWateringNumber(et4.getText().toString());
            //种子袋数
            vo.setBagNum(et5.getText().toString());
            vo.setEmergenceTime(et6.getText().toString());


            schemaJsonList.add(vo);
        }

        //采收
        for (int i = 0; i < layoutCaishou.getChildCount(); i++) {
            View view = layoutCaishou.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            EditText et3 = view.findViewById(R.id.et3);
            EditText et4 = view.findViewById(R.id.et4);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写采收重量");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写亩采收重量");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et3.getText().toString())) {
                showToast("请填写包装规格");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(et4.getText().toString())) {
                showToast("请填写批次");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setUseNumber(etUse.getText().toString());
            vo.setMuNumber(etMuUse.getText().toString());
            vo.setPackingSize(et3.getText().toString());
            vo.setBatch(et4.getText().toString());


            schemaJsonList.add(vo);
        }


        //加工包装
        for (int i = 0; i < layoutJiagong.getChildCount(); i++) {
            View view = layoutJiagong.getChildAt(i);
            TextView tvName = view.findViewById(R.id.tv_name);
            TextView tvCode = view.findViewById(R.id.tv_code);
            TextView tvYN = view.findViewById(R.id.tv_Y_N);
            TextView tvBzID = view.findViewById(R.id.tv_bz_id);
            EditText etUse = view.findViewById(R.id.et_use);
            EditText etMuUse = view.findViewById(R.id.et_mu_use);
            EditText et3 = view.findViewById(R.id.et3);
            EditText et4 = view.findViewById(R.id.et4);
            EditText et5 = view.findViewById(R.id.et5);
            EditText et6 = view.findViewById(R.id.et6);
            EditText et7 = view.findViewById(R.id.et7);
            EditText et8 = view.findViewById(R.id.et8);

            SchemaJsonVO vo = new SchemaJsonVO();
            if (StringUtil.isStrEmpty(etUse.getText().toString())) {
                showToast("请填写加工件数");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(etMuUse.getText().toString())) {
                showToast("请填写加工重量");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et3.getText().toString())) {
                showToast("请填写人均加工件数");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(et4.getText().toString())) {
                showToast("请填写包装箱（袋）");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et6.getText().toString())) {
                showToast("请填写出冰袋");
                schemaJsonList.clear();
                break;
            }

            if (StringUtil.isStrEmpty(et6.getText().toString())) {
                showToast("请填写包装绳");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et7.getText().toString())) {
                showToast("请填写包装材料费");
                schemaJsonList.clear();
                break;
            }
            if (StringUtil.isStrEmpty(et8.getText().toString())) {
                showToast("请填写冷库预冷费");
                schemaJsonList.clear();
                break;
            }

            vo.setName(tvName.getText().toString());
            vo.setType(tvCode.getText().toString());
            vo.setFarmOperationSchemeId(tvBzID.getText().toString());
            vo.setIsStandardEnforcement(tvYN.getText().toString());

            vo.setProcessedNumber(etUse.getText().toString());
            vo.setProcessedWeight(etMuUse.getText().toString());
            vo.setAvgProcessedNumber(et3.getText().toString());
            vo.setBoxNumber(et4.getText().toString());
            vo.setIcpPack(et5.getText().toString());
            vo.setPackingRope(et6.getText().toString());
            vo.setPackagingMaterialsFee(et7.getText().toString());
            vo.setColdStorageFee(et8.getText().toString());


            schemaJsonList.add(vo);
        }

        if (schemaJsonList != null && schemaJsonList.size() > 0)
            schemaListStr = JSON.toJSONString(schemaJsonList, false);
    }

    // 选择图片
    private void selectImage(int i) {
        select = i;
        if (StringUtil.isStrEmpty(imgs[select])) {
            Intent intent = new Intent(AddFarmingRecordActivityV2.this, ImageGridActivity.class);
            startActivityForResult(intent, REQUEST_CODE_SELECT);
        } else {
            new MaterialDialog.Builder(AddFarmingRecordActivityV2.this)
                    .title("提示")
                    .content("是否删除这张照片？")
                    .positiveText("删除")
                    .negativeText("取消")
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            imgs[select] = "";
                            Uri uri = Uri.parse("res://com.digitalchina.bigdata/" + R.drawable.selector_image_add);
                            sdvArray[select].setImageURI(uri);
                        }
                    })
                    .show();
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
            //添加图片返回
            if (data != null && requestCode == REQUEST_CODE_SELECT) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
                if (images != null && images.size() > 0) {
                    showDialog("正在上传图片...");
                    BusinessFile.imageCompressAndUpload(this, images.get(0).path, mHandler);
                }

            }
        }
    }


    private void initOptPicker() {

        //打开选择,本次允许选择的数量
        imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new GlideImageLoader());   //设置图片加载器
        imagePicker.setShowCamera(true);  //显示拍照按钮
        imagePicker.setCrop(false);        //允许裁剪（单选才有效）
        imagePicker.setMultiMode(false);    //是否多选模式


        listT.add("低于0℃");
        listT.add("0-5℃");
        listT.add("5-10℃");
        listT.add("10-15℃");
        listT.add("15-20℃");
        listT.add("20-25℃");
        listT.add("25-30℃");
        listT.add("30-35℃");
        listT.add("高于35℃");

        List<String> tempList = new ArrayList<>();
        tempList.add("晴");
        tempList.add("多云");
        tempList.add("阴");
        tempList.add("雨");
        tempList.add("雪");
        tempList.add("阵雨");
        tempList.add("雷阵雨");
        tempList.add("雨夹雪");
        tempList.add("小雨");
        tempList.add("中雨");
        tempList.add("大雨");
        tempList.add("暴雨");
        tempList.add("冻雨");
        tempList.add("阵雪");
        tempList.add("小雪");
        tempList.add("中雪");
        tempList.add("大雪");
        tempList.add("暴雪");
        tempList.add("浮尘");
        tempList.add("扬沙");
        tempList.add("沙尘暴");
        tempList.add("雾");
        tempList.add("浓雾");
        tempList.add("霾");

        for (int i = 0; i < listT.size(); i++) {
            listW.add(tempList);
        }


        // 天气
        pvWeather = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String select = listT.get(options1) + " " + listW.get(options1).get(option2);

                weather = listT.get(options1);
                weatherDescribe = listW.get(options1).get(option2);

                tvWeather.setText(select);
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();

        pvWeather.setPicker(listT, listW);


        // 物候期
        pvPhase = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String select = whList.get(options1).getPhaseName();
                phId = whList.get(options1).getId();
                phaseName = whList.get(options1).getPhaseName();
                tvPhenological.setText(select);
                farmList = whList.get(options1).getFarmOperation();
                tagAdapter.setData(farmList);
                tagAdapter.setSelectedList();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvPhase.setPicker(emptyList);

        // 农药
        pvNy = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = pesticideSchemeList.get(options1).getName();
                final String type = pesticideSchemeList.get(options1).getType();
                final String bzID = pesticideSchemeList.get(options1).getId();
                final String standard = pesticideSchemeList.get(options1).getSchemeStandard();

                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutNongyao.addView(newView(0, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutNongyao.addView(newView(0, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();

            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvNy.setPicker(emptyList);

        // 化肥
        pvHf = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = fertilizerSchemeList.get(options1).getName();
                final String type = fertilizerSchemeList.get(options1).getType();
                final String bzID = fertilizerSchemeList.get(options1).getId();
                final String standard = fertilizerSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutHuafei.addView(newView(1, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutHuafei.addView(newView(1, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvHf.setPicker(emptyList);

        // 大棚管理
        pvDp = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = manageItemsRowsSchemeList.get(options1).getName();
                final String type = manageItemsRowsSchemeList.get(options1).getType();
                final String bzID = manageItemsRowsSchemeList.get(options1).getId();
                final String standard = manageItemsRowsSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutDapeng.addView(newView(2, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutDapeng.addView(newView(2, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvDp.setPicker(emptyList);

        // 机械设备
        pvJxsb = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = machineryEquipmentSchemeList.get(options1).getName();
                final String type = machineryEquipmentSchemeList.get(options1).getType();
                final String bzID = machineryEquipmentSchemeList.get(options1).getId();
                final String standard = machineryEquipmentSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJxsb.addView(newView(3, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJxsb.addView(newView(3, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvJxsb.setPicker(emptyList);

        // 投入品
        pvTrp = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = inProductSchemeList.get(options1).getName();
                final String type = inProductSchemeList.get(options1).getType();
                final String bzID = inProductSchemeList.get(options1).getId();
                final String standard = inProductSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutTrp.addView(newView(4, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutTrp.addView(newView(4, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvTrp.setPicker(emptyList);

        // 技术方法-定值
        pvDz = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = colonizationSchemeList.get(options1).getName();
                final String type = colonizationSchemeList.get(options1).getType();
                final String bzID = colonizationSchemeList.get(options1).getId();
                final String standard = colonizationSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutDingzhi.addView(newView(8, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJsff.addView(newView(8, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvDz.setPicker(emptyList);

        // 技术方法-育苗
        pvYm = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = technicalMethodsSchemeList.get(options1).getName();
                final String type = technicalMethodsSchemeList.get(options1).getType();
                final String bzID = technicalMethodsSchemeList.get(options1).getId();
                final String standard = technicalMethodsSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJsff.addView(newView(5, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJsff.addView(newView(5, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvYm.setPicker(emptyList);

        // 采收
        pvCs = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = harvestPackagingSchemeList.get(options1).getName();
                final String type = harvestPackagingSchemeList.get(options1).getType();
                final String bzID = harvestPackagingSchemeList.get(options1).getId();
                final String standard = harvestPackagingSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutCaishou.addView(newView(6, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutCaishou.addView(newView(6, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvCs.setPicker(emptyList);

        // 加工包装
        pvJg = new OptionsPickerView.Builder(AddFarmingRecordActivityV2.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(final int options1, int option2, int options3, View v) {

                final String name = processedPackagingSchemeList.get(options1).getName();
                final String type = processedPackagingSchemeList.get(options1).getType();
                final String bzID = processedPackagingSchemeList.get(options1).getId();
                final String standard = processedPackagingSchemeList.get(options1).getSchemeStandard();
                new MaterialDialog.Builder(activity)
                        .title("参考标准")
                        .content(standard)
                        .positiveText("已按标准执行")
                        .negativeText("未按标准执行")
                        .onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJiagong.addView(newView(7, name, type, "YES", standard, bzID));
                            }
                        })
                        .onNegative(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                layoutJiagong.addView(newView(7, name, type, "NO", standard, bzID));
                            }
                        })
                        .show();
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();
        pvJg.setPicker(emptyList);

        tagAdapter = new TagAdapter<PlanProductVO.FarmOperationBean>(farmList) {

            @Override
            public View getView(FlowLayout parent, int position, PlanProductVO.FarmOperationBean vo) {
                TextView tv = (TextView) mInflater.inflate(R.layout.view_text_view,
                        flowLayout, false);
                tv.setText(vo.getFarmName());
                return tv;
            }
        };

        flowLayout.setAdapter(tagAdapter);
    }

    public String getImages() {

        String s = "";
        for (String img : imgs) {
            if (!StringUtil.isStrEmpty(img))
                s += img + ",";
        }

        if (!StringUtil.isStrEmpty(s))
            s = s.substring(0, s.length() - 1);

        return s;
    }

    //农事操作方案
    public void getAgriculturalSchema() {

        if (StringUtil.isStrEmpty(farmOperationId)) {
            showToast("请选择作物管理项目");
            return;
        }

        HttpParams params = new HttpParams();
        params.put("farmOperationId", farmOperationId);

        OkHttpUtil.post(activity, URL.URL_GET_AGRICULTURAL_SCHEMA, "正在获取...", params, mHandler, MSG_S_3, MSG_F_3);
    }


    /**
     * 保存数据
     */
    private void saveFarm() {
        if (AdminXML.getFarmOperation(activity).equals("1")) {

            if (StringUtil.isStrEmpty(landParcelInfoId)) {
                showToast("请选择地块");
                return;
            }
        }


        if (StringUtil.isStrEmpty(varietyId)) {
            showToast("请选择品种");
            return;
        }

        if (StringUtil.isStrEmpty(operationDate)) {
            showToast("请选择操作日期");
            return;
        }

        if (StringUtil.isStrEmpty(weather)) {
            showToast("请选择天气");
            return;
        }

        if (StringUtil.isStrEmpty(phId)) {
            showToast("请选择物候期");
            return;
        }


        if (StringUtil.isStrEmpty(farmOperationId)) {
            showToast("请选择作物管理项目");
            return;
        }

        muNumber = etMuNum.getText().toString();
        if (StringUtil.isStrEmpty(muNumber)) {
            showToast("请填写亩数");
            return;
        }

        hours = etWorkTime.getText().toString();
        if (StringUtil.isStrEmpty(hours)) {
            showToast("请填写工时");
            return;
        }

        peopleNum = etPeopleNum.getText().toString();
        if (StringUtil.isStrEmpty(peopleNum)) {
            showToast("请填写人数");
            return;
        }

        member = etPeopleName.getText().toString();
        if (StringUtil.isStrEmpty(member)) {
            showToast("请填写人员");
            return;
        }


        getSchemaJsonList();
        if (layoutNongyao.getChildCount() > 0 || layoutHuafei.getChildCount() > 0 || layoutDapeng.getChildCount() > 0 || layoutJxsb.getChildCount() > 0 ||
                layoutTrp.getChildCount() > 0 || layoutJsff.getChildCount() > 0 || layoutCaishou.getChildCount() > 0 || layoutJiagong.getChildCount() > 0) {
            if (StringUtil.isStrEmpty(schemaListStr)) {
                return;
            }
        }


        farmingOperationsimgs = getImages();

        if (StringUtil.isStrEmpty(farmingOperationsimgs)) {
            showToast("至少上传一张图片");
            return;
        }


        specification = etMsgInfo.getText().toString();

        BusinessPlan.farmingSaveV3(AddFarmingRecordActivityV2.this, productionId, landParcelInfoId, varietyId, operationDate,
                weather, weatherDescribe, phId, phaseName, farmOperationId, muNumber, hours, peopleNum, member,
                farmingOperationsimgs, specification, schemaListStr, id, mHandler);
    }
}
